package org.example.registery.impl;

import lombok.extern.slf4j.Slf4j;
import org.example.registery.ServerRegistry;
import org.example.utils.ServiceUtils;

import java.net.InetSocketAddress;

/**
 * Nacos服务注册接口
 *
 * @author feixiang.li
 */
@Slf4j
public class NacosServerRegistryImpl implements ServerRegistry {

    @Override
    public void register(String serviceName, InetSocketAddress inetSocketAddress) {
        log.info("服务名称:{},-注册到当前服务的ip:{}", serviceName, inetSocketAddress);
        ServiceUtils.registerService(serviceName, inetSocketAddress);
    }

    @Override
    public InetSocketAddress getService(String serviceName) {
        log.info("服务名称:{},-来获取当前服务的ip", serviceName);
        // 这里一般是从注册中心获取-zookeeper 获取 服务的ip,这里也可以添加 负载均衡策略等等。这里默认返回一个ip
        return ServiceUtils.getService(serviceName);
    }
}
